package haxe.util.benchmark;
import haxe.util.EnumStack;
import haxe.util.Stack;

class ArrayVsStack extends BenchmarkHelper, implements Benchmark
{
	var a:Array<TestData>;
	var s:haxe.util.Stack<TestData>;
	var e:EnumStack<TestData>;
	
	public function new( iterations:Int )
	{
		super( iterations );
	}
	
	/*public function runPushAndPop():Void
	{
		s = new Stack<TestData>();
		a = new Array<TestData>();
		var ops:Array<Bool> = new Array<Bool>();
		
		for( i in 0...100 )
		{
			s.add(new TestData("name"+i,i));
			a.push(new TestData("name"+i,i));
		}
		
		for ( i in 0...iterations )
		{
			ops.push( Math.random() > 0.4 ); 
		}
		
		init("Stack.push & pop["+this.iterations+"]");
		for( j in 0...5 )
		{
			for ( i in ops )
			{
				if ( i )
					s.push(new TestData("name",Math.random()));
				else
					s.pop();
			}
		}
		done();
		
		init("Array.push & pop["+this.iterations+"]");
		for( j in 0...5 )
		{
			for ( i in ops )
			{
				if ( i )
					a.push(new TestData("name",Math.random()));
				else
					a.pop();
			}
		}
		done();		
		
		trace(a.length+" : "+s.size+" ops : "+ops.length );
	}*/
	
	public function runAdd():Void
	{
		s = new Stack<TestData>();
		a = new Array<TestData>();
		e = new EnumStack<TestData>();
		
		init("Stack.add["+this.iterations+"]");
		for ( i in 0...iterations )
			s.add(new TestData("name"+i,i));
		done();
		
		init("Array.push["+this.iterations+"]");
		for ( i in 0...iterations )
			s.add(new TestData("name"+i,i));
		done();
		
		init("EnumStack.push["+this.iterations+"]");
		for ( i in 0...iterations )
			e.push(new TestData("name"+i,i));
		done();
	}
	
	public function runPop():Void
	{
		s = new Stack<TestData>();
		a = new Array<TestData>();
		e = new EnumStack<TestData>();
		for ( i in 0...iterations )
		{
			var d:TestData = new TestData("name"+i,i);
			s.add(d);
			a.push(d);
			e.push(d);
		}
		
		init("Array.pop["+this.iterations+"]");
		while( a.length > 0 )
			a.pop();
		done();
		
		init("Stack.pop["+this.iterations+"]");
		while( s.isEmpty() )
			s.pop();
		done();
		
		init("EnumStack.pop["+this.iterations+"]");
		for ( i in 0...e.length() )
			e.pop();
		done();
	}
}